<?php
/**
 * Created by PhpStorm.
 * User: chy
 * Date: 2017/10/19
 * Time: 下午6:04
 */
?>
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Created by PhpStorm.
 * Date: 2018/9/13
 * Time: 下午6:44
 */
class c_specimen_admin extends CI_Controller{
    function __construct (){
        parent::__construct();
    }

    function index()
    {
//        $this->load->model('m_bacteria');
//        $image=$this->m_bacteria->getdata();
//        $data['image']=$image;

        $keywords = null;     //查询值
        $selecttype = null;     //用来存放查询方式（对应表中的属性名）
        $search = 0;    //通过search将数据查询分为搜索和分页查询
        $page = 0;

        $page = (int) $page;

        //分页+查询url设置
        $segments = $this->uri->uri_to_assoc();
        $data['segments'] = $segments;
        //print_r($segments);
        if($search)
        {
            //echo '62';
            //redirect('login');
            $segments['selecttype'] = $selecttype;
            $segments['keywords']  = $keywords;
        }
        else
        {
            $segments['selecttype'] = !empty($segments['selecttype']) ? $segments['selecttype'] : '';
            $segments['keywords'] = !empty($segments['keywords']) ? $segments['keywords'] : '';
            //echo "72  : ".$segments['keywords'];
        }
        //print_r($segments);

        //现在只能实现类别+关键字查询
        $search_url = $segments['selecttype'].'/'.$segments['keywords'];
        //计算查询条件
        //$options = array('conditions' => null);

        //处理查询条件options

        //按照分类查询(只有分类和分类关键字都有)
        //echo '87';
        //带有关键字查询
        if(!empty($segments['selecttype']))
        {
            $options['selecttype'] = $segments['selecttype'];
            $options['keywords'] = $segments['keywords'];
        }
        //不带有关键字查询
        else if(empty($segments['selecttype']))
        {
            $options['selecttype'] = '';
            $options['keywords'] = '';
        }
        else
        {
            echo "查询条件错误！books.php line 85";
        }
        //echo "line 98";
        //print_r($options);

        //只按照关键字查询

        //print_r($options);

        //调试使用
        $data['temp'] =array(
            'keywords'=>  $options['keywords'],
            'selecttype' => $options['selecttype'],
            'search'=> $this->input->post('search'),
            'page'=> $page
        ) ;
        $data['options'] = $options;
        $data['keywords'] = $segments['keywords'];
        $data['selecttype'] = $segments['selecttype'] ;


        //分页开始的数据行:$page_offset
        if($page)
        {
            $page_offset = $page -1;
        }
        else if(!empty($segments['page']))
        {
            $page_offset = (int) $segments['page'];
        }
        else
        {
            $page_offset = 0;
        }
        if($page_offset < 0)
        {
            $page_offset = 0;
        }

        //分页url
        $this->load->helper('url');

        $base_url = site_url('c_specimen/index/page').'/';

        //每页显示条数
        $per_page = 40;

        //数据总数
        $this->load->model('m_bacteria');
        $data['total_rows'] = $this->m_bacteria->getDataCount_frontspec($options);
        $data['test'] = $this->m_bacteria->getDataCount_ispec($options);
        //总页数
        $data['total_pages'] = ceil($data['total_rows'] / $per_page);

        //当前页(input)
        $data['page'] = $page_offset+1;
        $data['page'] = ($data['page']>$data['total_pages'] && $data['total_pages']>0) ? $data['total_pages'] : $data['page'];

        //第一页   最后一页   前一页   后一页
        $data['page_first'] = $base_url.'0'.$search_url;
        $data['page_last'] = $base_url.($data['total_pages'] - 1).$search_url;
        $data['page_prev'] = ($data['page'] > 1) ? $base_url.($data['page']-2).$search_url : $data['page_first'];
        $data['page_next'] = ($data['page'] < $data['total_pages']) ? $base_url.($data['page']).$search_url : $data['page_last'];

        //当前页
        $data['cur_page'] = $base_url.($data['page'] - 1).$search_url;

        //当前页起始数据号码
        $data['show_start'] = ($data['page'] - 1)*$per_page +1;

        //当前页结束数据号
        $data['show_end'] = ($page_offset < $data['total_pages'] - 1) ? ($data['show_start'] + $per_page - 1) : $data['total_rows'];

//        //图书结果集
//        $bac_del = 1;
        $data['specimen'] = $this->m_bacteria->find_bacteria_frontspec($options,$per_page,($data['page'] - 1)*$per_page);
//        $data['bacteria'] = $this->m_bacteria->find_bacteria_front($options,$per_page,($data['page'] - 1)*$per_page);
//        //$options,$count=20, $offset=0, $is_delete=0
//        $data['select'] = array('count'=>$per_page,'offset'=>($data['page'] - 1)*$per_page,'bac_del'=>$bac_del);
        $this->load->view('bacteria/v_specimen_admin',$data);
        
    }
    function queryById($specimen_id){
        $this->load->model('m_bacteria');
        $data['specimen'] = $this->m_bacteria->queryspecById_front($specimen_id);
        $this->load->view('bacteria/v_specimen_info_admin',$data);
        //echo $data['result'];
    }
    function queryByIdmod($specimen_id){
        $this->load->model('m_bacteria');
        $data['specimen'] = $this->m_bacteria->queryspecById_front($specimen_id);
        $this->load->view('bacteria/v_specimen_info_mod',$data);
        //echo $data['result'];
    }
    function queryByIdadd($specimen_id){
        $this->load->model('m_bacteria');
        $data['specimen'] = $this->m_bacteria->queryspecById_front($specimen_id);
        $this->load->view('bacteria/v_specimen_info_add',$data);
        //echo $data['result'];
    }
    function resultadd(){
        //$this->load->model('m_bacteria');
        //$data['specimen'] = $this->m_bacteria->queryspecById_front($specimen_id);
        $this->load->view('bacteria/v_specimen_image');
        //echo $data['result'];
    }
    function queryImageById($image_id){
        $this->load->model('m_bacteria');
        $data['result'] = $this->m_bacteria->queryById_front($image_id);
        $data['image'] = $this->m_bacteria->queryImageById_front($image_id);
        $this->load->view('bacteria/v_front_bac_image',$data);
    }
    function queryByIdImageUpdata($specimen_id){
        $this->load->model('m_bacteria');
        $data['specimen'] = $this->m_bacteria->queryspecById_front($specimen_id);
        $this->load->view('bacteria/v_specimen_mod',$data);
    }
    function queryByIdImageDelete($specimen_id){
        $this->load->model('m_bacteria');
        $this->m_bacteria->deleteImageByIdspec($specimen_id);
        //$this->load->view('bacteria/v_success');
        redirect('c_specimen_admin/');
    }
    function queryByIdUpdata($data_id){
        $this->load->model('m_bacteria');
        $data['result'] = $this->m_bacteria->querydataById_front($data_id);
//        echo $data_id;
//        $data['image'] = $this->m_bacteria->queryImageById_front($data_id);
        $this->load->view('bacteria/v_data_updata',$data);
    }
    function queryByIdDelete($data_id){
        $this->load->model('m_bacteria');
//        $data['result'] = $this->m_bacteria->queryById_front($data_id);
//        $data['image'] = $this->m_bacteria->queryImageById_front($image_id);
//        $this->load->view('bacteria/v_front_bac_image',$data);
        $this->m_bacteria->deleteById($data_id);
        $this->load->view('bacteria/v_success');
    }
    function getPost(){
        if($_POST) {
            $keywords = $_POST['keywords'];     //查询值
            //用来存放查询方式（对应表中的属性名）
        }
        $this->queryFind(urldecode($keywords),0);
        //echo $keywords;
        //echo $selecttype;
    }

    function queryFind($keywords,$page){
        $search = 1;    //通过search将数据查询分为搜索和分页查询

        $page = (int) $page;
        $segments['keywords']  = urldecode($keywords);
        $data['segments'] = $segments;
        $search_url = $segments['keywords'];

        $options['keywords'] = $segments['keywords'];

        $data['temp'] =array(
            'keywords'=>  $options['keywords'],
            'search'=> 1,
            'page'=> $page
        ) ;
        $data['options'] = $options;
        $data['keywords'] = $segments['keywords'];

        //print_r($data['options']);
        //分页开始的数据行:$page_offset
        if($page)
        {
            $page_offset = $page ;
        }
        else if(!empty($segments['page']))
        {
            $page_offset = (int) $segments['page'];
        }
        else
        {
            $page_offset = 0;
        }
        if($page_offset < 0)
        {
            $page_offset = 0;
        }

        //分页url
        $this->load->helper('url');
        $base_url = site_url('c_specimen/index/page').'/';

        //每页显示条数
        $per_page = 40;

        //数据总数
        $this->load->model('m_bacteria');
        $data['total_rows'] = $this->m_bacteria->getDataCount_frontspec($options);
        $data['test'] = $this->m_bacteria->getDataCount_ispec($options);
        //总页数
        $data['total_pages'] = ceil($data['total_rows'] / $per_page);

        //当前页(input)
        $data['page'] = $page_offset+1;
        $data['page'] = ($data['page']>$data['total_pages'] && $data['total_pages']>0) ? $data['total_pages'] : $data['page'];
        // print_r($data['page']);
        //第一页   最后一页   前一页   后一页
        $data['page_first'] = $base_url.$search_url.'/0';
        $data['page_last'] = $base_url.$search_url.'/'.($data['total_pages'] - 1);
        $data['page_prev'] = ($data['page'] > 1) ? $base_url.$search_url.'/'.($data['page']-2) : $data['page_first'];
        $data['page_next'] = ($data['page'] < $data['total_pages']) ? $base_url.$search_url.'/'.($data['page']) : $data['page_last'];
        //$data['page_next'] = ($data['page'] < $data['total_pages']) ? $base_url.($data['page']).$search_url : $data['page_last'];
        //当前页
        $data['cur_page'] = $base_url.$search_url.'/'.($data['page'] - 1);

        //当前页起始数据号码
        $data['show_start'] = ($data['page'] - 1)*$per_page +1;

        //当前页结束数据号
        $data['show_end'] = ($page_offset < $data['total_pages'] - 1) ? ($data['show_start'] + $per_page - 1) : $data['total_rows'];

        //图书结果集
        $bac_del = 1;
        $data['specimen'] = $this->m_bacteria->find_bacteria_frontspec($options,$per_page,($data['page'] - 1)*$per_page);
//        $data['bacteria'] = $this->m_bacteria->find_bacteria_front($options,$per_page,($data['page'] - 1)*$per_page);
//        //$options,$count=20, $offset=0, $is_delete=0
//        $data['select'] = array('count'=>$per_page,'offset'=>($data['page'] - 1)*$per_page,'bac_del'=>$bac_del);
        $this->load->view('bacteria/v_specimen_admin',$data);
       
    }

}
?>
